package com;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class QueryString {

    private StringBuilder query = new StringBuilder();

    public QueryString() {
    }

    public synchronized void add(String name,String value){

        query.append('&');

        encoode(name, value);

    }

    private synchronized void encoode(String name,String value) {

        try {
            query.append(URLEncoder.encode(name,"UTF-8"));

            query.append('=');

            query.append(URLEncoder.encode(value,"UTF-8"));

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }

    public synchronized String getQuery(){

        return query.toString();

    }

    @Override
    public String toString() {
        return getQuery();
    }
}
